package com.guomao.controller;


import com.guomao.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Array;
import java.util.Arrays;

@Controller
public class ControllerA {

/*    @RequestMapping("/handlea")
    public String handleA(HttpServletRequest request) {
        String username = request.getParameter("username");
        String password = request.getParameter("password");

        request.setAttribute("username", username);
        request.setAttribute("password", password);

        return "main";
    }*/


    //在控制器方法的形参列表中定义同名请求参数变量
    @RequestMapping("/handlea")
//    public String handleA(String username, String password, String hobby, Model m) {
//    public String handleA(String username, String password, Model m) {
//    public String handleA(String username, String password, String[] hobby) {
    public String handleA(String username, String password, String hobby) {

//        m.addAttribute("username", username);
//        m.addAttribute("password", password);
//        m.addAttribute("hobby", hobby);
//        System.out.println(Arrays.toString(hobby));
//        System.out.println(hobby);

//        ['code','run','study']
//        hobby=code&hobby=run&hobby=study

//        System.out.println(username + ":" + password + ":" + Arrays.toString(hobby));
        return "main";
    }


    @RequestMapping("/handleb")
    public String handleb(@RequestParam("name") String username, @RequestParam("pswd") String password, String hobby, Model m) {
//    public String handle10(String username, String password, String[] hobby) {
//        System.out.println(username + "," + password + "," + hobby);
//        System.out.println(username + "," + password + "," + Arrays.toString(hobby));
        System.out.println(username);
        System.out.println(password);
        m.addAttribute("username", username);
        m.addAttribute("password", password);
        return "main";
    }


    @RequestMapping("/handlec")
    public String handlec(@RequestParam(value = "pageno", required = false, defaultValue = "1") String pageno, @RequestParam(value = "pagesize", required = false, defaultValue = "10") String pagesize, Model m) {

        m.addAttribute("pageno", pageno);
        m.addAttribute("pagesize", pagesize);
        return "main";
    }

    @RequestMapping("/handled")
    public String handlec(User u, Model m) {
        m.addAttribute("user", u);
        System.out.println(u);
        return "main";
    }
}
